package com.powernode.controller;

import com.powernode.dto.CategoryDto;
import com.powernode.dto.ProductDto;
import com.powernode.dto.Result;
import com.powernode.feign.PMSFeign;
import com.powernode.service.IndexCarouselService;
import com.powernode.service.IndexContentService;
import com.powernode.vo.IndexCarouselVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cms/app/index")
public class AppIndexController {
    @Autowired
    private IndexCarouselService indexCarouselService;
    @Autowired
    private IndexContentService indexContentService;
    @Autowired
    private PMSFeign PMSFeign;
//    @Autowired
//    private HttpServletRequest request;


    /**
     * 获取指定数量的首页轮播图
     */
    @GetMapping("/carousels/{num}")
    public Result<List<IndexCarouselVo>> listCarouselsForIndex(@PathVariable Integer num){
        //System.out.println(request.getRequestURI()); // uri:/cms/app/index/carousels/5
        //System.out.println(request.getRequestURL()); // url:http://192.168.100.2:8002/cms/app/index/carousels/5
        return Result.success(indexCarouselService.listCarouselsForIndex(num));
    }

    /**
     * 根据商品类型获取首页商品集合
     */
    @GetMapping("/contents/{contentType}/{num}")
    public Result<List<ProductDto>> listProductsForIndex(@PathVariable Integer contentType, @PathVariable Integer num){
        return indexContentService.getContentsForIndex(contentType, num);
    }

    /**
     * 获取首页商品一级分类
     */
    @GetMapping("/categories/level1")
    public Result<List<CategoryDto>> listCategoriesForIndex(){
        return PMSFeign.listCategoriesByLevel(1);
    }
}
